<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Hexo, NexT" />





  <link rel="alternate" href="/atom.xml" title="大牙的杂货铺" type="application/atom+xml" />






<meta name="description" content="dialog是一个可以创建对话框的工具，需要手动安装，yum源安装即可。 系统默认自带whiptail也可实现对话框的创建 每个对话框提供的输出有两种形式： 将所有输出到stderr，不显示到屏幕； 使用退出状态码，OK为0，NO为1，ESC为255。    语法说明1Usage: dialog --common-op">
<meta property="og:type" content="article">
<meta property="og:title" content="使用dialog创建交互式shell对话框">
<meta property="og:url" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/index.html">
<meta property="og:site_name" content="大牙的杂货铺">
<meta property="og:description" content="dialog是一个可以创建对话框的工具，需要手动安装，yum源安装即可。 系统默认自带whiptail也可实现对话框的创建 每个对话框提供的输出有两种形式： 将所有输出到stderr，不显示到屏幕； 使用退出状态码，OK为0，NO为1，ESC为255。    语法说明1Usage: dialog --common-options --boxType &quot;Text&quot; Height Width --b">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/01-msgbox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/02-inputbox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/03-textbox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/04-yesnobox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/05-menubox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/06-fselect.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/07-checklist.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/08-passwordbox.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/09-calendar.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/10-gauge.png">
<meta property="og:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/11-from1.png">
<meta property="og:updated_time" content="2018-01-30T14:14:05.585Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="使用dialog创建交互式shell对话框">
<meta name="twitter:description" content="dialog是一个可以创建对话框的工具，需要手动安装，yum源安装即可。 系统默认自带whiptail也可实现对话框的创建 每个对话框提供的输出有两种形式： 将所有输出到stderr，不显示到屏幕； 使用退出状态码，OK为0，NO为1，ESC为255。    语法说明1Usage: dialog --common-options --boxType &quot;Text&quot; Height Width --b">
<meta name="twitter:image" content="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/01-msgbox.png">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":true},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/"/>





  <title>使用dialog创建交互式shell对话框 | 大牙的杂货铺</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
	
	<a href="https://github.com/mengdaya"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">大牙的杂货铺</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off"
             placeholder="搜索..." spellcheck="false"
             type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="孟庆宇">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="大牙的杂货铺">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">使用dialog创建交互式shell对话框</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-01-21T15:54:26+08:00">
                2018-01-21
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"> 本文总阅读量</i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,005
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  9
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <ul>
<li><code>dialog</code>是一个可以创建对话框的工具，需要手动安装，yum源安装即可。</li>
<li>系统默认自带<code>whiptail</code>也可实现对话框的创建</li>
<li>每个对话框提供的输出有两种形式：<ul>
<li>将所有输出到stderr，不显示到屏幕；</li>
<li>使用退出状态码，OK为0，NO为1，ESC为255。</li>
</ul>
</li>
</ul>
<h1 id="语法说明"><a href="#语法说明" class="headerlink" title="语法说明"></a>语法说明</h1><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Usage: dialog --common-options --boxType <span class="string">"Text"</span> Height Width --box-specific-option</span><br></pre></td></tr></table></figure>
<ul>
<li><code>--common-options</code> 通用选项</li>
<li><code>--boxType</code> 窗体类型</li>
<li><code>&quot;Text&quot;</code>窗体的标题</li>
<li><code>Height</code> 窗体的高度（字符个数）</li>
<li><code>Width</code> 窗体宽度（字符个数）</li>
</ul>
<h1 id="选项"><a href="#选项" class="headerlink" title="选项"></a>选项</h1><h2 id="通用选项"><a href="#通用选项" class="headerlink" title="通用选项"></a>通用选项</h2><p>这个选项用来设置dialog box的背景、颜色和标题等。</p>
<ul>
<li><code>--title &lt;title&gt;</code>：窗体的标题</li>
<li><code>--backtitle &lt;backtitle&gt;</code>：窗体的背景标题</li>
<li><code>--colors</code>：使用颜色 <code>\Z</code>表示开始，<code>\Zn</code>表示结束。解读嵌入式<code>\Z</code>的对话框中的特殊文本序列，序列由下面的字符0-7, b，B, u, U等组成，恢复正常的设置使用<code>\Zn</code>。</li>
<li><code>--no-shadow</code>：禁用窗体的阴影效果</li>
<li><code>--shadow</code>：启用窗体的阴影效果</li>
<li><code>--insecure</code>：输入部件的密码时，使用星号来代表每个字符。</li>
<li><code>--no-cancel</code>：设置在输入框、菜单和复选框中不显<code>cancel</code>项。</li>
<li><code>--nook</code> 没有ok键</li>
<li><code>--clear</code>：完成清屏操作，在框体显示结束后，清除框体，这个参数只能单独使用，不能和别的参数联合使用。</li>
<li><code>--ok-label &lt;str&gt;</code>：覆盖使用OK按钮标签，换做其它字符。</li>
<li><p><code>--cancel-label &lt;str&gt;</code>：功能同上。</p>
</li>
<li><p><code>--begin &lt;y&gt; &lt;x&gt;</code>：指定对话框左上角在屏幕上的坐标。</p>
</li>
<li><code>--timeout &lt;secs&gt;</code>：超时（返回的错误代码），如果用户在指定的时间内没有给出相应动作，就按超时处理。</li>
<li><code>--defaultno</code>：设定光标在yesno对话框的默认位置为no</li>
<li><code>--default-item string</code> ：设定在复选框中的默认值</li>
<li><code>--sleep &lt;secs&gt;</code>：窗体的超时时间，如果用户没有在超时时间内进行选择，将会退出并返回一个错误码</li>
<li><code>--stderr</code>：以标准错误方式输出。</li>
<li><code>--stdout</code>：以标准方式输出。</li>
<li><code>--default-item &lt;str&gt;</code>：设置在一份清单、表格或菜单中的默认项目，通常在框中的第一项是默认的。</li>
</ul>
<h2 id="窗体类型选项"><a href="#窗体类型选项" class="headerlink" title="窗体类型选项"></a>窗体类型选项</h2><p>常见的对话框控件选项如下所示：</p>
<ul>
<li><code>--calendar</code>：提供了一个日历，让你可以选择日期。</li>
<li><code>--checklist</code>：允许你显示一个选项列表，每个选项都可以被单独的选择(复选框)。</li>
<li><code>--from</code>：允许建立一个带标签的文本字段，并要求填写。</li>
<li><code>--fselect</code>：提供一个路径，让你选择浏览的文件。</li>
<li><code>--gauge</code>：显示一个表，呈现出完成的百分比，就是显示出进度。</li>
<li><code>--infobox</code>：显示消息后，（没有等待响应）对话框立刻返回，但不清除屏幕(信息框)。</li>
<li><code>--inputbox</code>：让用户输入文本(输入框)。</li>
<li><code>--inputmenu</code>：提供一个可供用户编辑的菜单（可编辑的菜单框）。</li>
<li><code>--menu</code>：显示一个列表供用户选择(菜单框)。</li>
<li><code>--msgbox</code>：显示一条消息，并要求用户选择一个确定按钮(消息框)。</li>
<li><code>--pause</code>：显示一个表格用来显示一个指定的暂停期的状态。</li>
<li><code>--passwordbox</code>：显示一个输入框，它隐藏文本。</li>
<li><code>--passwordfrom</code>：显示一个来源于标签并且隐藏的文本字段。</li>
<li><code>--radiolist</code>：提供一个菜单项目组，只有一个项目，可以选择(单选框)。</li>
<li><code>--tailbox</code>：在一个滚动窗口文件中使用tail命令来显示文本。</li>
<li><code>--tailboxbg</code>：跟tailbox类似，但是在background模式下操作。</li>
<li><code>--textbox</code>：在带有滚动条的文本框中显示文件的内容(文本框)。</li>
<li><code>--timebox</code>：提供一个窗口，选择小时、分钟、秒。</li>
<li><code>--yesno</code>：提供一个带有yes和no按钮的简单信息框(是/否框)。</li>
</ul>
<h1 id="使用示例"><a href="#使用示例" class="headerlink" title="使用示例"></a>使用示例</h1><h2 id="创建消息框"><a href="#创建消息框" class="headerlink" title="创建消息框"></a>创建消息框</h2><ul>
<li>语法</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"&lt;message box title&gt;"</span> --msgbox <span class="string">"&lt;text to show&gt;"</span> &lt;height&gt; &lt;width&gt;</span><br></pre></td></tr></table></figure>
<ul>
<li>实例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --backtitle <span class="string">"Test the first message box"</span> --title <span class="string">"Test Message Box"</span> --colors --ok-label <span class="string">"YES"</span> --msgbox  <span class="string">"Create a message box with dialog. Choose \Z1YES\Zn to continue."</span> 10 60</span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/01-msgbox.png" alt=""></p>
<h2 id="创建输入框"><a href="#创建输入框" class="headerlink" title="创建输入框"></a>创建输入框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --inputbox text height width</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line">userName=$(dialog --backtitle <span class="string">"Add a user"</span>  --title <span class="string">"Username"</span> --inputbox <span class="string">"Please input a username"</span> 10 30  --stdout)</span><br><span class="line"><span class="built_in">echo</span> <span class="string">"Username is:"</span> <span class="variable">$userName</span></span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/02-inputbox.png" alt=""></p>
<h2 id="创建文本信息框"><a href="#创建文本信息框" class="headerlink" title="创建文本信息框"></a>创建文本信息框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --textbox file height width</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --textbox /etc/fstab 20 80</span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/03-textbox.png" alt=""></p>
<h2 id="创建yesno对话框"><a href="#创建yesno对话框" class="headerlink" title="创建yesno对话框"></a>创建yesno对话框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --yesno text height width</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"yes/no"</span> --no-shadow --yesno <span class="string">"Delete the file /tmp/test.txt?"</span> 10 30</span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/04-yesnobox.png" alt=""></p>
<h2 id="创建一个菜单栏"><a href="#创建一个菜单栏" class="headerlink" title="创建一个菜单栏"></a>创建一个菜单栏</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --menu text height width menu-height tag1 item1 tag2 item2 …</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Pick a choice"</span> --menu <span class="string">"Choose one"</span> 12 35 5 A <span class="string">"Display the disk usage"</span> B <span class="string">"Display the meminfo"</span> C <span class="string">"Quit"</span></span><br><span class="line"><span class="comment"># 进入菜单后按A、B、C可定位到某一个条目上，标准输出是tag</span></span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/05-menubox.png" alt=""></p>
<h2 id="创建文件选框"><a href="#创建文件选框" class="headerlink" title="创建文件选框"></a>创建文件选框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --fselect filepath height width</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Pick one file"</span> --fselect /root/ 7 40</span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/06-fselect.png" alt=""></p>
<h2 id="创建复选框"><a href="#创建复选框" class="headerlink" title="创建复选框"></a>创建复选框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --checklist <span class="string">"Test"</span> height width menu-height tag1 item1 tag2 item2 …</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --backtitle <span class="string">"Checklist"</span> --checklist <span class="string">"Test"</span> 20 50 10 Memory Memory_Size 1 Dsik Disk_Size 2</span><br></pre></td></tr></table></figure>
<ul>
<li>效果</li>
</ul>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/07-checklist.png" alt=""></p>
<h2 id="创建密码框"><a href="#创建密码框" class="headerlink" title="创建密码框"></a>创建密码框</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --passwordbox text height width [init]</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Password"</span> --passwordbox <span class="string">"Please give a password for the new user:"</span> 10 35</span><br></pre></td></tr></table></figure>
<p>密码暴露出来不安全，所以通常我们会加上一个安全选项<code>--insecure</code>，将每个字符用<code>*</code>来显示。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Password"</span> --insecure --passwordbox <span class="string">"Please give a password for the new user:"</span> 10 30</span><br></pre></td></tr></table></figure>
<ul>
<li><p>效果</p>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/08-passwordbox.png" alt=""></p>
<h2 id="创建一个日历框"><a href="#创建一个日历框" class="headerlink" title="创建一个日历框"></a>创建一个日历框</h2></li>
<li><p>格式</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --calendar <span class="string">"Date"</span> height width day month year</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<p>显示当前日期</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Calendar"</span> --calendar <span class="string">"Date"</span> 5 50</span><br></pre></td></tr></table></figure>
<p>显示指定日期</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Calendar"</span> --calendar <span class="string">"Date"</span> 5 50 1 2 2013</span><br></pre></td></tr></table></figure>
<ul>
<li><p>效果</p>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/09-calendar.png" alt=""></p>
<h2 id="创建一个进度框"><a href="#创建一个进度框" class="headerlink" title="创建一个进度框"></a>创建一个进度框</h2></li>
<li><p>格式</p>
</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --gauge text height width  [&lt;percent&gt;]</span><br></pre></td></tr></table></figure>
<ul>
<li>示例</li>
</ul>
<p>固定进度显示</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"installation pro"</span> --gauge <span class="string">"installation"</span> 10 30 10</span><br></pre></td></tr></table></figure>
<p>实时显示</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> &#123;1..100&#125; ;<span class="keyword">do</span> <span class="built_in">echo</span> <span class="variable">$i</span>;<span class="keyword">done</span> | dialog --title <span class="string">"installation pro"</span> --gauge <span class="string">"installation"</span> 10 30</span><br></pre></td></tr></table></figure>
<p>拷贝100个文件</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#!/bin/bash</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">declare</span> -i percent=0</span><br><span class="line">install -<span class="built_in">cd</span> /tmp/<span class="built_in">test</span></span><br><span class="line"></span><br><span class="line">(</span><br><span class="line"><span class="keyword">for</span> file <span class="keyword">in</span> /etc/*;<span class="keyword">do</span></span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$&#123;percent&#125;</span> -le 100 ];<span class="keyword">then</span></span><br><span class="line">        cp -r <span class="variable">$&#123;file&#125;</span> /tmp/<span class="built_in">test</span>/ 2&gt;/dev/null</span><br><span class="line">        <span class="built_in">echo</span> XXX</span><br><span class="line">		<span class="comment">#  两个XXX之间的内容替换标题</span></span><br><span class="line">        <span class="built_in">echo</span> <span class="string">"Copy the file <span class="variable">$&#123;file&#125;</span> ... "</span></span><br><span class="line">        <span class="built_in">echo</span> XXX</span><br><span class="line">        <span class="built_in">echo</span> <span class="variable">$&#123;percent&#125;</span></span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">    ((percent=percent+1))</span><br><span class="line">    sleep 0.1</span><br><span class="line"></span><br><span class="line"><span class="keyword">done</span></span><br><span class="line">    ) | dialog --title <span class="string">"Coping..."</span> --gauge <span class="string">"Starting to copy files ... "</span> 6 50 0</span><br></pre></td></tr></table></figure>
<ul>
<li><p>效果</p>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/10-gauge.png" alt=""></p>
</li>
</ul>
<h2 id="创建表单"><a href="#创建表单" class="headerlink" title="创建表单"></a>创建表单</h2><ul>
<li>格式</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">dialog --form text height width formheight [ label y x item y x flen ilen ] ...</span><br></pre></td></tr></table></figure>
<p>其中：<code>flen</code>表示<code>field length</code>，定义了选定字段中显示的长度；<code>ilen</code>表示<code>input-length</code>, 定义了在外地输入的数据允许的长度。使用<code>up/down</code>（或<code>ctrl/ N</code>，<code>ctrl/ P</code>）在使用领域之间移动，使用tab键在窗口之间切换。</p>
<ul>
<li>示例</li>
</ul>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">dialog --title <span class="string">"Add a user"</span> --form <span class="string">"Please input the infomation of new user:"</span> 12 40 4 \</span><br><span class="line">  <span class="string">"Username:"</span> 1  1 <span class="string">""</span> 1  15  15  0 \</span><br><span class="line">  <span class="string">"Full name:"</span> 2  1 <span class="string">""</span> 2  15  15  0 \</span><br><span class="line">  <span class="string">"Home Dir:"</span> 3  1 <span class="string">""</span> 3  15  15  0 \</span><br><span class="line">  <span class="string">"Shell:"</span>    4   1 <span class="string">""</span> 4  15  15  0</span><br></pre></td></tr></table></figure>
<ul>
<li><p>效果</p>
<p><img src="/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/11-from1.png" alt=""></p>
</li>
</ul>
<h2 id="综合应用示例"><a href="#综合应用示例" class="headerlink" title="综合应用示例"></a>综合应用示例</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#! /bin/bash</span></span><br><span class="line"></span><br><span class="line">yesno() </span><br><span class="line">&#123;</span><br><span class="line">    dialog --title <span class="string">"First screen"</span> --backtitle <span class="string">"Test Program"</span> --clear --yesno \</span><br><span class="line">        <span class="string">"Start this test program or not ? \nThis decesion have to make by you."</span> 16 51</span><br><span class="line"></span><br><span class="line">    <span class="comment"># yes is 0, no is 1 , esc is 255</span></span><br><span class="line">    result=$?</span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$result</span> -eq 1 ] ; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 1;</span><br><span class="line">    <span class="keyword">elif</span> [ <span class="variable">$result</span> -eq 255 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 255;</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line">    username;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">username() </span><br><span class="line">&#123;</span><br><span class="line">    cat /dev/null &gt;/tmp/test.username</span><br><span class="line">    dialog --title <span class="string">"Second screen"</span> --backtitle <span class="string">"Test Program"</span> --clear --inputbox \</span><br><span class="line">        <span class="string">"Please input your username (default: hello) "</span> 16 51 <span class="string">"hello"</span> 2&gt;/tmp/test.username</span><br><span class="line"></span><br><span class="line">    result=$?</span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$result</span> -eq 1 ] ; <span class="keyword">then</span></span><br><span class="line">        yesno;</span><br><span class="line">    <span class="keyword">elif</span> [ <span class="variable">$result</span> -eq 255 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 255;</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line">    password;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">password() </span><br><span class="line">&#123;</span><br><span class="line">    cat /dev/null &gt;/tmp/test.password</span><br><span class="line">    dialog  --insecure --title <span class="string">"Third screen"</span> --backtitle <span class="string">"Test Program"</span> --clear --passwordbox \</span><br><span class="line">        <span class="string">"Please input your password (default: 123456) "</span> 16 51 <span class="string">"123456"</span> 2&gt;/tmp/test.password</span><br><span class="line"></span><br><span class="line">    result=$?</span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$result</span> -eq 1 ] ; <span class="keyword">then</span></span><br><span class="line">        username;</span><br><span class="line">    <span class="keyword">elif</span> [ <span class="variable">$result</span> -eq 255 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 255;</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line">    occupation;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">occupation() </span><br><span class="line">&#123;</span><br><span class="line">    cat /dev/null &gt;/tmp/test.occupation</span><br><span class="line">    dialog --title <span class="string">"Forth screen"</span> --backtitle <span class="string">"Test Program"</span> --clear --menu \</span><br><span class="line">        <span class="string">"Please choose your occupation: (default: IT)"</span> 16 51 3 \</span><br><span class="line">        IT <span class="string">"The worst occupation"</span> \</span><br><span class="line">        CEO <span class="string">"The best occupation"</span> \</span><br><span class="line">        Teacher <span class="string">"Not the best or worst"</span>  2&gt;/tmp/test.occupation</span><br><span class="line"></span><br><span class="line">    result=$?</span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$result</span> -eq 1 ] ; <span class="keyword">then</span></span><br><span class="line">        password;</span><br><span class="line">    <span class="keyword">elif</span> [ <span class="variable">$result</span> -eq 255 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 255;</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line"></span><br><span class="line">    finish;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">finish() </span><br><span class="line">&#123;</span><br><span class="line">    dialog --title <span class="string">"Fifth screen"</span> --backtitle <span class="string">"Test Program"</span> --clear --msgbox \</span><br><span class="line">        <span class="string">"Congratulations! The test program has finished!\n Username: <span class="variable">$(cat /tmp/test.username)</span>\n Password: <span class="variable">$(cat /tmp/test.password)</span>\n Occupation: <span class="variable">$(cat /tmp/test.occupation)</span>"</span> 16 51</span><br><span class="line"></span><br><span class="line">    result=$?</span><br><span class="line">    <span class="keyword">if</span> [ <span class="variable">$result</span> -eq 1 ] ; <span class="keyword">then</span></span><br><span class="line">        occupation</span><br><span class="line">    <span class="keyword">elif</span> [ <span class="variable">$result</span> -eq 255 ]; <span class="keyword">then</span></span><br><span class="line">        <span class="built_in">exit</span> 255;</span><br><span class="line">    <span class="keyword">fi</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">yesno;</span><br></pre></td></tr></table></figure>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>有钱任性，请我吃包辣条</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="孟庆宇 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="孟庆宇 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    
      <div>
        <ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者：</strong>
    孟庆宇
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/" title="使用dialog创建交互式shell对话框">http://linuxgeeks.github.io/2018/01/21/2018-01-21-155425-使用dialog创建交互式shell对话框/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>
    本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/3.0/" rel="external nofollow" target="_blank">CC BY-NC-SA 3.0</a> 许可协议。转载请注明出处！
  </li>
</ul>

      </div>
    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/01/20/2018-01-20-172607-chmod权限被改为000后的恢复/" rel="next" title="chmod权限被改为000后的恢复">
                <i class="fa fa-chevron-left"></i> chmod权限被改为000后的恢复
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/01/21/2018-01-21-223237-Linux下socks5搭建和应用/" rel="prev" title="Linux下socks5搭建和应用">
                Linux下socks5搭建和应用 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
        
  <div class="bdsharebuttonbox">
    <a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
    <a href="#" class="bds_douban" data-cmd="douban" title="分享到豆瓣网"></a>
    <a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友"></a>
    <a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>
    <a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a>
    <a href="#" class="bds_tieba" data-cmd="tieba" title="分享到百度贴吧"></a>
    <a href="#" class="bds_twi" data-cmd="twi" title="分享到Twitter"></a>
    <a href="#" class="bds_fbook" data-cmd="fbook" title="分享到Facebook"></a>
    <a href="#" class="bds_more" data-cmd="more"></a>
    <a class="bds_count" data-cmd="count"></a>
  </div>
  <script>
    window._bd_share_config = {
      "common": {
        "bdText": "",
        "bdMini": "2",
        "bdMiniList": false,
        "bdPic": ""
      },
      "share": {
        "bdSize": "16",
        "bdStyle": "0"
      },
      "image": {
        "viewList": ["tsina", "douban", "sqq", "qzone", "weixin", "twi", "fbook"],
        "viewText": "分享到：",
        "viewSize": "16"
      }
    }
  </script>

<script>
  with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='//bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>

      
    </div>
  </div>


          </div>
          


          
  


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
      <div id="sidebar-dimmer"></div>
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/avatar.jpg"
                alt="孟庆宇" />
            
              <p class="site-author-name" itemprop="name">孟庆宇</p>
              <p class="site-description motion-element" itemprop="description">书山有路勤为径，学海无涯苦作舟</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">109</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">23</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">56</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          
            <div class="feed-link motion-element">
              <a href="/atom.xml" rel="alternate">
                <i class="fa fa-rss"></i>
                RSS
              </a>
            </div>
          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/mengdaya" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:yourname@gmail.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
            
          </div>

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-inline">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-globe"></i>
                友情链接
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.ibm.com/developerworks/cn/" title="IBM developerWorks" target="_blank">IBM developerWorks</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://iissnan.com/progit/" title="Pro Git" target="_blank">Pro Git</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.freeoa.net/index/" title="freeOA" target="_blank">freeOA</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ttlsa.com/" title="运维生存时间" target="_blank">运维生存时间</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.361way.com/" title="运维之路" target="_blank">运维之路</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.yiibai.com/" title="易百教程" target="_blank">易百教程</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.centoscn.com/" title="CentOS中文站" target="_blank">CentOS中文站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.linuxprobe.com/" title="Linux就该这么学" target="_blank">Linux就该这么学</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.netingcn.com/" title="网络进行时" target="_blank">网络进行时</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.ruanyifeng.com/blog/" title="阮一峰的网络日志" target="_blank">阮一峰的网络日志</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.liaoxuefeng.com" title="廖雪峰的官方网站" target="_blank">廖雪峰的官方网站</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yihui.name/cn/" title="谢益辉的博客" target="_blank">谢益辉的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://coolshell.cn" title="酷壳" target="_blank">酷壳</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#语法说明"><span class="nav-number">1.</span> <span class="nav-text">语法说明</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#选项"><span class="nav-number">2.</span> <span class="nav-text">选项</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#通用选项"><span class="nav-number">2.1.</span> <span class="nav-text">通用选项</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#窗体类型选项"><span class="nav-number">2.2.</span> <span class="nav-text">窗体类型选项</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#使用示例"><span class="nav-number">3.</span> <span class="nav-text">使用示例</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建消息框"><span class="nav-number">3.1.</span> <span class="nav-text">创建消息框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建输入框"><span class="nav-number">3.2.</span> <span class="nav-text">创建输入框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建文本信息框"><span class="nav-number">3.3.</span> <span class="nav-text">创建文本信息框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建yesno对话框"><span class="nav-number">3.4.</span> <span class="nav-text">创建yesno对话框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建一个菜单栏"><span class="nav-number">3.5.</span> <span class="nav-text">创建一个菜单栏</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建文件选框"><span class="nav-number">3.6.</span> <span class="nav-text">创建文件选框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建复选框"><span class="nav-number">3.7.</span> <span class="nav-text">创建复选框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建密码框"><span class="nav-number">3.8.</span> <span class="nav-text">创建密码框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建一个日历框"><span class="nav-number">3.9.</span> <span class="nav-text">创建一个日历框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建一个进度框"><span class="nav-number">3.10.</span> <span class="nav-text">创建一个进度框</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建表单"><span class="nav-number">3.11.</span> <span class="nav-text">创建表单</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#综合应用示例"><span class="nav-number">3.12.</span> <span class="nav-text">综合应用示例</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">文章总结于网络，转载请注明出处</span>

  
</div>









        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user">本站访客</i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye">本站总访问量</i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="true"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  








  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  
<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';        
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>


  

  

  

  

</body>
</html>
